package com.hsjk.szwj.module.system.controller.admin.poster;

import com.hsjk.szwj.framework.common.pojo.CommonResult;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.system.controller.admin.poster.vo.AdminCreatePosterReqVO;
import com.hsjk.szwj.module.system.controller.admin.poster.vo.AdminPosterDetailRespVO;
import com.hsjk.szwj.module.system.controller.admin.poster.vo.AdminPosterPageReqVO;
import com.hsjk.szwj.module.system.controller.admin.poster.vo.AdminPosterPageRespVO;
import com.hsjk.szwj.module.system.controller.admin.poster.vo.AdminUpdatePosterReqVO;
import com.hsjk.szwj.module.system.service.poster.IPosterConfig;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.hsjk.szwj.framework.common.pojo.CommonResult.success;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/12/11 15:01
 **/
@Tag(name = "后台管理端 - 海报配置相关接口")
@RestController
@RequestMapping("/system/poster")
@Validated
public class AdminPosterController {

    @Resource
    private IPosterConfig posterConfig;

    @PostMapping("/create")
    @Operation(summary = "创建海报")
    @PreAuthorize("@ss.hasPermission('system:poster:create')")
    public CommonResult<Boolean> createPoster(@RequestBody @Valid AdminCreatePosterReqVO reqVO) {
        return success(posterConfig.createPoster(reqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "更新海报")
    @PreAuthorize("@ss.hasPermission('system:poster:update')")
    public CommonResult<Boolean> updatePoster(@RequestBody @Valid AdminUpdatePosterReqVO reqVO) {
        return success(posterConfig.updatePoster(reqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除海报")
    @PreAuthorize("@ss.hasPermission('system:poster:delete')")
    public CommonResult<Boolean> deletePoster(@RequestParam("id") Long id) {
        posterConfig.deletePoster(id);
        return success(true);
    }

    @PostMapping("/page-poster")
    @Operation(summary = "分页获取海报列表")
    @PreAuthorize("@ss.hasPermission('system:poster:query')")
    public CommonResult<PageResult<AdminPosterPageRespVO>> getAdminPosterPage(
            @RequestBody @Valid AdminPosterPageReqVO reqVO) {
        return success(posterConfig.getAdminPosterPage(reqVO));
    }

    @GetMapping("/get-poster-detail")
    @Operation(summary = "获取海报详情")
    @PreAuthorize("@ss.hasPermission('system:poster:query')")
    public CommonResult<AdminPosterDetailRespVO> getAdminPosterDetail(@RequestParam Long id) {
        return success(posterConfig.getAdminPosterDetail(id));
    }
}
